package guoanmaker.operator.business.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorUser;
import guoanmaker.operator.business.model.ReturnResult;
import guoanmaker.operator.business.service.OperatorUserService;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import guoanmaker.operator.helper.common.util.JasyptHelper;
import io.swagger.annotations.ApiOperation;

/**
 * 2017.7.19
 * 
 * @author zj
 *
 */
@RestController
@RequestMapping(ApiController.OPERATOR_USER)
public class OperatorLoginController {



	@Resource
	private OperatorUserService operatorUserService;

	@Autowired
	private HttpServletRequest request;

	@ApiOperation(value = "后台登录接口", notes = "登录判断账号是否正常")
	@RequestMapping(value = "/operatorLogin",method = RequestMethod.POST)
	public AjaxJson operatorLogin(String username, String password) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorUserService.validatUandP(username, password));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}



	// 发送验证码
	@ApiOperation(value = "发送短信接口", notes = "发送短信")
	@RequestMapping(value ="/sendVeryMessage",method = RequestMethod.POST)
	public AjaxJson sendVeryMessage(String account) {
		AjaxJson ajaxJson=new AjaxJson();
		ReturnResult returnResult = new ReturnResult();
		try {
			returnResult = operatorUserService.sendVeryMessage(account);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}

		return ajaxJson;

	}
	@ApiOperation(value = "保存菜单项测试用")
	@RequestMapping(value ="/savepid",method = RequestMethod.POST)
	public AjaxJson savepid(String name) {
		AjaxJson ajaxJson=new AjaxJson();
		ReturnResult returnResult = new ReturnResult();
		try {
		
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorUserService.savepid(name));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		
		return ajaxJson;
		
	}
	
	

	// 忘记密码
	@ApiOperation(value = "忘记密码接口", notes = "设置用户密码")
	@RequestMapping(value ="/forgetPassword",method = RequestMethod.POST)
	public AjaxJson forgetPassword(String username, String password) {
		AjaxJson ajaxJson=new AjaxJson();
		ReturnResult returnResult = new ReturnResult();
		try {
			returnResult = operatorUserService.forgetPassword(username, password);
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(returnResult);
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData(returnResult);
		}
		return ajaxJson;
	}

	@ApiOperation(value = "验证账号是否存在")
	@RequestMapping(value = "/validateUsernameIs",method = RequestMethod.POST)
	public AjaxJson validateUsernameIs(String username) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorUserService.validateUsernameIs(username));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "验证验证码存在接口")
	@RequestMapping(value = "/vlidateCodeIsexist",method = RequestMethod.POST)
	public AjaxJson vlidateCodeIsexist(String username,String code) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorUserService.vlidateCodeIsexist(username,code));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}

}
